/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author tank
 */

//: maopao.java
import java.util.*;
import java.math.*;

/** maopao arithmetic算法
 * @author xiaoweimy
 * @version 1.0
*/

public class maopao {
  static int[] nums;
  static int size;
  static Random rand = new Random();
  static int pRand(){
  	return Math.abs(rand.nextInt()) % 20 + 1 ;
  }
  static int pRand(int mod1){
  	return Math.abs(rand.nextInt()) % mod1 + 1 ;
  }
maopao(){
	//赋初值nums
	size = 10;
	nums = new int[10];
	System.out.println("Original array's length is: " + 10);
	//System.out.println("nums is : " + nums);//the stack address
	System.out.println("Original array is: ");
  for (size=0; size<nums.length; size++){
		nums[size] = pRand();
		//显示数组中的值
  	System.out.print(nums[size] + " ");
  }
}
maopao(int mod,int count){
	//赋初值nums
	size = count;
	nums = new int[count];
	System.out.println("Original array's length is: " + 20);
	//System.out.println("nums is : " + nums);
	System.out.println("Original array is: ");
  for (size=0; size<nums.length; size++){
		nums[size] = pRand(mod);
		//显示数组中的值
  	System.out.print(nums[size] + " ");
  }
}

void suanfa(){
	//冒泡算法
	int t;
  for (int a=1; a<size; a++){
		for (int b=size - 1; b>=a; b--){
			if (nums[b-1]> nums[b]){//如果次序颠倒
				//则交换元素
				t = nums[b-1];
				nums[b-1] = nums[b];
				nums[b] = t;
			}
		}
  }
    //显示排序后的数组
  System.out.println("\nSorted array is: ");
  for(int size = 0; size < nums.length; size ++)
  	System.out.print(nums[size] + " ");
}

 public static void main(String[] args) {
	if(args.length == 2 && Integer.parseInt(args[0]) >0 && Integer.parseInt(args[0]) <10000){
		if (Integer.parseInt(args[1]) >0 && Integer.parseInt(args[1]) <10000){
			maopao mp = new maopao(Integer.parseInt(args[0]),Integer.parseInt(args[1]));
			mp.suanfa();
		}
	}else{
		System.out.println("Usage: java maopao mod count");
		System.out.println("(mod is relate on the size of the numbers.)\n"
			+"(count is the amount of the numbers.)");
		maopao mp = new maopao();
		mp.suanfa();
 	 }
 }
}